package com.wwdx.controller.admin;

import com.wwdx.controller.base.BaseController;
import com.wwdx.model.WwdxPersonalModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author liguoliang
 * @date 2017/6/16.
 */
@Controller
@RequestMapping("/system/whitepurchase")
public class WhitePurchaseController extends BaseController{

    /**
     * 清空白名单
     */
    @RequestMapping("/clear")
    public String clear(Long userid){
        wwdxPersonalService.getWhiteList(userid);
        return "redirect:/system/whitepurchase/white_purchase_list";
    }
    
    /**
     * 白名单列表
     */
    @RequestMapping("/white_purchase_list")
    public ModelAndView whitePurchaseList(WwdxPersonalModel model,
                                            @RequestParam(value = "page", defaultValue = "1") int page,
                                            @RequestParam(value = "rows",defaultValue = "10") int rows){
        
        ModelAndView mav = new ModelAndView();
        model.setWhite(1);
        mav.addObject("listSize",  wwdxPersonalService.selectModelCount(model));
        mav.addObject("list",  wwdxPersonalService.selectModelList(model,page,rows));
        return mav;
    }

    /**
     * 跳转添加页面
     */
    @RequestMapping(value = "/white_purchase_edit")
    public ModelAndView whitePurchaseEdit() {
        return new ModelAndView();
    }

    /**
     * 白名单设置
     */
    @RequestMapping("/white_purchase_save")
    public String whitePurchaseSave(Long userid,Integer white){
        WwdxPersonalModel wwdxPersonalModel = wwdxPersonalService.getById(userid);
        wwdxPersonalModel.setWhite(white);
        wwdxPersonalService.update(wwdxPersonalModel);
        return "redirect:/system/whitepurchase/white_purchase_list";
    }
}